
import java.util.Scanner;

public class fibArray3 {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) 
	{
		int min=0;
		int max=10000;
		int [] fibArray = new int[26];	
		fibArray[0]=1;
		int n=getNumber(min,max);  
		
		for ( int i=1, n1=0 , n2=1, n3 = 1 ; i< fibArray.length ; i++, n1=n2, n2=n3, n3=n2+n1 )
		{
			fibArray[i]= n3;
			
		}	
		
		for (int i=1; i<fibArray.length; i++) 
		{
			int nr= n % fibArray[i-1];
			int dif= fibArray[i]-fibArray[i-1];
			
			if(n >= fibArray[i-1] && n <= fibArray[i])
			{
				if (n == fibArray[i] || n == fibArray[i-1]){
					System.out.println("Congrats, you entered "+n+", which is a fibinacci number!");
					break;
				}
				else if (nr < (double)1/2* (double)dif ){
					System.out.println("The closest number is "+ fibArray[i-1]);
					break;
				}
				else if(nr > (double)1/2* (double)dif ){
					System.out.println("The closest number is "+ fibArray[i]);
					break;
				}
				else if(nr==(double)1/2* (double)dif ){
					System.out.println("your number was exactly between "+ fibArray[i-1]+" and "+fibArray[i]);
				break;
				}
			}
		}
			
			
			
			//			int nr= number % fibArray[i-1];
//			System.out.println(fibArray[i]);
////			if (0==nr)
////			{
////				System.out.println("Congrats, "+number+" is a fibinacci number!");
////				break;
////			}
//			
//			if ( (double) fibArray[i-1]* (.5)>nr && )
//			{
//				int c=fibArray[i-1];
//				System.out.println(number + " is closest to "+c);
//					break;
			
			
//			if()
		
		
		
	} 
		
	
	private static int getNumber(int min, int max)
	{
		boolean valid;
		int x=0;
		do{
			valid=true;
			System.out.println("Enter an integer between "+ min +" and " + max+ " :");
			x=sc.nextInt();
			if( x>min && x<max)
			{
				valid=true;
			}
			else 
			{
				System.out.println("HEY! That's not right! Try again.");
				valid=false;
			}
		}while (!valid);
		return x;
	}
}
